package com.lsy.weizhi2.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.lsy.weizhi2.R;
import com.lsy.weizhi2.picture.ImageInfo;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.List;


/**
 * Created by 嗨哟 on 2016/12/17.
 */
public class MyImagesAdapter extends BaseAdapter {
    private Context context;
    private List<ImageInfo> list_images;
    private LayoutInflater inflater;
    public MyImagesAdapter(Context context, List<ImageInfo> list_images) {
        this.context = context;
        this.list_images = list_images;
        inflater=LayoutInflater.from(context);
    }
    public void Updata(List<ImageInfo> list_images){
        this.list_images=list_images;
        this.notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        return list_images==null?0:list_images.size();
    }

    @Override
    public Object getItem(int i) {
        return list_images.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if(view==null){
            viewHolder=new ViewHolder();
            view=inflater.inflate(R.layout.myimagesitem,viewGroup,false);
            viewHolder.images_iv= (ImageView) view.findViewById(R.id.images_iv);
            viewHolder.images_info= (TextView) view.findViewById(R.id.images_info);
            view.setTag(viewHolder);
            AutoUtils.autoSize(view);
        }else{
            viewHolder= (ViewHolder) view.getTag();
        }
        viewHolder.images_info.setText(list_images.get(i).getBucketDisplayName());
        Glide.with(context).load(list_images.get(i).getPath()).diskCacheStrategy(DiskCacheStrategy.ALL).into(viewHolder.images_iv);
        return view;
    }
    class ViewHolder {
        ImageView images_iv;
        TextView images_info;
    }
}
